import { reactive } from "vue";
import { defineStore } from "pinia";
import type { TLanguage } from "@/plugins/element";

export const useLanguageStore = defineStore(
  "languageStore",

  () => {
    //定义响应式状态
    const languageState = reactive({
      lanuage: "zh-cn"
    });

    const getLanuage = computed(() => languageState.lanuage);

    const setLanuage = (lanuage: TLanguage) => {
      languageState.lanuage = lanuage;
    };

    return {
      languageState,
      getLanuage,
      setLanuage
    };
  },

  {
    persist: {
      storage: localStorage, //状态数据持久化保存在本地中
      pick: ["languageState.lanuage"] // pick表示获取状态树中那些状态
    }
  }
);
